﻿@model IEnumerable<Citi.Scheduler.WebUi.Models.LibraryModel>
@{
    var types = Enum.GetValues(typeof(Citi.Scheduler.Domain.LibraryType)).Cast<Citi.Scheduler.Domain.LibraryType>();
}
<script type="text/javascript">
    $(function () {
        $("[rel=tooltip]").tooltip({ placement: 'right' });
    });
</script>
<p>* Move the pointer over the version to see the details</p>

<table class="table table-bordered table-striped">
    <tr>
        <th rowspan="2" style="line-height: 50px;">
            Name
        </th>
        <th colspan="@types.Count()">
            Last Version
        </th>
        <th rowspan="2" style="line-height: 50px;">
            Actions
        </th>
    </tr>
    <tr>
        @foreach (var type in types)
        {
            <th>
                @type.GetDescription()
            </th>
        }
    </tr>
    @foreach (var item in Model)
    {
        <tr>
            <td>
                @Html.DisplayFor(modelItem => item.Name)
            </td>
            @foreach (var type in types)
            {
                <td style="position:relative; width:@(30/types.Count())%;">
                    @{
                        var version = item.GetLastVersionByType(type);
                        if (version == null)
                        {
                            <text>-</text>
                            continue;
                        }
                        else
                        {
                            var description = version.ChangeDescription.Length > 150 
                                ? string.Concat(version.ChangeDescription.Substring(0,150), "...") 
                                : version.ChangeDescription;
                            
                            <span rel="tooltip" title="@(string.Format("Release Notes: {0} ({1} - {2})", description, version.User.Name, version.Date.ToString("dd/MM/yyyy")))">@version.Version</span>
                        }
                      }
                </td>
            }
            <td>
                @Ajax.ActionLink("Edit", "ActionForm", new { id = item.Id }, new AjaxOptions { UpdateTargetId = "divUpdateLibrary", OnBegin = "openUpdateLibraryDialog" }, new { @class = "" })
                |
                @Ajax.ActionLink("Delete", "Delete", new { id = item.Id }, new AjaxOptions { UpdateTargetId = "divIndexLibrary", Confirm = "Are you sure?" }, new { @class = "" })
                |
                @Ajax.ActionLink("Show versions", "Index", "LibraryVersion", new { libraryId = item.Id }, new AjaxOptions
           {
               UpdateTargetId = "divIndexLibraryHistory",
               OnBegin = string.Concat("openLibraryVersionsDialog('", item.Id, "');")
           }, new { @class = "" })
            </td>
        </tr>
    }
</table>
